﻿using System.ComponentModel;

namespace PMS.WebApi.Models
{
    public class BaseResult
    {
        public int code { get; set; }
        public bool success { get; set; }
        public string message { get; set; }
    }

    public class ResultData : BaseResult
    {
        public object data { get; set; }
    }

    public class ResultData<T> : BaseResult
    {
        public T data { get; set; }
    }

    public class ResultMsg : BaseResult { }

    public enum ResultStatus
    {
        [Description("系统异常")]
        Exception = -1,
        [Description("登录信息已失效")]
        LoginTimeout = -99,
        [Description("二次登录校验已过期")]
        SecondLoginTimeout = -98,
        [Description("操作失败")]
        Fail = 0,
        [Description("操作成功")]
        Success = 1
    }

    public static class ResultUtils
    {
        public static ResultData ToErrorResult(this string msg, int code = -1)
        {
            ResultData resultModel = new ResultData
            {
                code = code,
                success = false,
                data = null,
                message = msg
            };
            return resultModel;
        }

        public static ResultData ToSuccessResult(this object data, string msg = "")
        {
            ResultData resultModel = new ResultData
            {
                code = 1,
                success = true,
                data = data,
                message = msg
            };
            return resultModel;
        }
    }
}
